package Leetcode_Second_Brush;

import java.util.ArrayList;
import java.util.List;

public class Solution006 {
    public String convert(String s, int numRows) {
        if (numRows == 1) {
            return s;
        }

        List<StringBuilder> list = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            list.add(new StringBuilder());
        }
        int direction = 1;
        int index = 0;
        for (char c : s.toCharArray()) {
            list.get(index).append(c);
            if (index + direction < 0 || index + direction == numRows)
                direction = -direction;
            index += direction;
            System.out.println(index);
        }
        StringBuilder result = new StringBuilder();
        for (StringBuilder sb : list) {
            result.append(sb);
        }
        return result.toString();
    }
}
